package cn.itcast.wanxinp2p.consumer.controller;

import cn.itcast.wanxinp2p.consumer.service.ConsumerService;
import cn.itcast.wanxinp2p.api.ConsumerApi;
import cn.itcast.wanxinp2p.common.domain.RestResponse;
import cn.itcast.wanxinp2p.dto.comsumer.ConsumerRegisterDTO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户中心服务
 * @author 一方通行
 */
@RestController
public class ConsumerController implements ConsumerApi {

    /**
     * 用户中心服务Service层
     */
    @Autowired
    private ConsumerService consumerService;

    /**
     * 用户中心服务实现保存功能
     * @param consumerRegisterDTO 前端用户注册信息
     */
    @ApiOperation("用户注册")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "consumerRegisterDTO",
                    value = "用户注册",
                    required = true,
                    dataType = "ConsumerRegisterDTO",
                    paramType = "body")
    })
    @Override
    @PostMapping(value = "/consumers")
    public RestResponse register(@RequestBody ConsumerRegisterDTO consumerRegisterDTO) {
        consumerService.register(consumerRegisterDTO);
        return RestResponse.success();
    }
}
